//
//  NSArray+LYAdd.h
//  LYDevelopKit
//
//  Created by 李阳 on 2018/5/26.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSArray<ObjectType> (LYAdd)

/// 求和
- (CGFloat)sum;
/// 求最大值
- (CGFloat)max;
/// 求最小值
- (CGFloat)min;
/// 求平均值
- (CGFloat)avg;
/// 去重
- (NSArray *_Nullable)distinctUnionOfObjects;
/// 按容量分割数组 
- (NSArray<NSArray<ObjectType> *> *)separatedByCount:(NSUInteger)max;
/// 反转数组
- (NSArray<ObjectType> *)reverseArray;

@end

@protocol LYCompareDelegate <NSObject>

- (NSComparisonResult)compare:(id)anObject;

@end

@interface NSMutableArray<ObjectType> (LYAdd)

/**
 有序添加元素

 @param object 所要添加的元素
 @param primaryKeyPath 元素判重的key nil表示不去重
 @param ascending 是否升序
 @return 返回此元素在数组中排序后的位置
 */
- (NSUInteger)addObjectOrderly:(ObjectType<LYCompareDelegate>)object
                primaryKeyPath:(NSString *)primaryKeyPath
                     ascending:(BOOL)ascending;

- (BOOL)replaceObjectPassingTest:(BOOL (^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate withObject:(ObjectType)object ;

@end

NS_ASSUME_NONNULL_END
